#pragma once

#include "ScriptAdapter.h"
#include <string>

extern "C" {
#include ".\lua\lua.h"
#include ".\lua\lualib.h"
#include ".\lua\lauxlib.h"
}

typedef int (*luaFunction) (lua_State *L);
typedef const luaL_Reg* luaLib;

class CLua:public CScript
{
public:
	CLua();
	~CLua();
public:
	virtual void Init();
	virtual void UnInit();
	virtual bool RunFile(const char* filePath);
	virtual bool RunScript(char* script);
	virtual std::wstring GetLastError();
	virtual void SetLastError(const wchar_t* _Format,...);
	virtual void SetOutputConsole(CConsoleDlg* dev);
	bool ExportFunction(const char* funcName,luaFunction func);
	bool ExportModule(const char* libName,const luaLib lib);
protected:
	bool RegisterEssential();
	bool LoadFile(const char* filePath);
	bool Run();
private:
	lua_State* m_LuaState;
	std::wstring LastErrorStr;
};


